//
//  AuditInfoView.swift
//  Pods
//
//  Created by eme on 2017/5/11.
//
//

import UIKit
import SnapKit
import RxSwift
import RickonCore

/// 需要弹出 登陆 认证 等信息的按钮界面
open class AuditInfoView: UIView {
    
    var info_Btn = UIButton(type: .custom)
    let disposeBag = DisposeBag()
    ///选择跳转路径
    var actionTitle:String{
        get{
            switch AppData.appState {
            case .tourists:
                return "登录/注册"
            case .notAudit:
                return "立即认证"
            case .auditing:
                return "审核中，立即查看"
            case .auditfailed:
                return "审核失败，立即查看"
            default:
                // 说明已经审核通过，然后就不需要显示该界面
                self.removeFromSuperview()
                return ""
            }
        }
    }
    func setupSubviews() {
        self.backgroundColor = UIColor.white
        info_Btn.titleLabel?.font = UIFont(name: Theme.font.bold, size: 14)
        info_Btn.setTitleColor(UIColor.white, for: .normal)
        info_Btn.changeBorderColor(UIColor.clear, cornerRadius: 4, borderWidth: 1)
        info_Btn.backgroundColor = Theme.btn.normal
        self.addSubview(self.info_Btn)
        info_Btn.snp.makeConstraints { (make) in
            make.width.equalTo(145)
            make.centerY.equalToSuperview().offset(-55)
            make.centerX.equalToSuperview()
            make.height.equalTo(35)
        }
        self.info_Btn
            .rx.tap
            .subscribe(onNext: {( _ ) in
                _ = "authaction".openURL()
            })
            .disposed(by: disposeBag)
        NotificationCenter.default.addObserver(self, selector: #selector(AuditInfoView.appdatachangedResult(notification:)), name: NSNotification.Name(rawValue: AppConfig.notification.appdatachangedKey), object: nil)
    }
    
    public  static func showByView(supView:UIView) {
        let auditInfV = AuditInfoView()
        supView.addSubview(auditInfV)
        auditInfV.snp.makeConstraints { (make) in
            make.center.equalToSuperview()
            make.leading.equalToSuperview()
            make.top.equalToSuperview()
        }
        auditInfV.info_Btn.setTitle(auditInfV.actionTitle, for: .normal)
        
    }
    
    open override func awakeFromNib() {
        setupSubviews()
    }
    open override func draw(_ rect: CGRect) {
        
    }
    public override init(frame: CGRect) {
        super.init(frame: frame)
        setupSubviews()
    }
    public required  init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    ///该界面只需要修改按钮的标题
    func appdatachangedResult(notification: NSNotification) {
        self.info_Btn.setTitle(self.actionTitle, for: .normal)
    }
}
